/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testproject;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author marco
 */
public class Servant implements Service{
    LinkedBlockingQueue<String> queue;
    
    public Servant(){
        queue = new LinkedBlockingQueue<>();
    }
    
    
    @Override
    public void enqueue(String task) {
        try {
            queue.put(task); // Adds the specified element to the tail of this queue, waiting if necessary for space to become available.
        } catch (InterruptedException ex) {
            Logger.getLogger(Servant.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public String dequeue(){
        String task = null;
        try {
            task = queue.take(); //Retrieves and removes the head of this queue, waiting if no elements are present on this queue.
        } catch (InterruptedException ex) {
            Logger.getLogger(Servant.class.getName()).log(Level.SEVERE, null, ex);
        }
        return task;
    }
    
}
